var templateParams = {
    tableTheads:["组名", "执行机", "创建时间", "创建人", "备注", "操作"],
    btnTools:[{
        type:"primary",
        size:"M",
        id:"add-object",
        iconFont:"&#xe600;",
        name:"添加执行机组"
    },{
        type:"primary",
        size:"M",
        id:"download-slave",
        iconFont:"&#xe641;",
        name:"下载执行机端"
    }, {
        type:"danger",
        size:"M",
        id:"batch-op",
        iconFont:"&#xe6bf;",
        name:"批量操作"
    }],
    formControls:[{
        edit:true,
        label:"ID",
        objText:"idText",
        input:[{
            hidden:true,
            name:"id"
        }]
        },
        {
            required:true,
            label:"组名",
            input:[{
                name:"group_name"
            }]
        },
        {
            edit:true,
            label:"创建时间",
            objText: "create_timeText"
        },
        {
            label:"备注",
            textarea:[{
                name:"mark"
            }]
        }
    ]};

var columnsSetting = [
    {
        "data":null,
        "render":function(data, type, full, meta){
            return checkboxHmtl(data.group_name, data.id, "selectGroup");
        }},
    {"data": "id"},
    ellipsisData("group_name"),
    {
        "data":"slave_count",
        "render":function(data, type, full, meta){
            var context =
                [{
                    type:"default",
                    size:"M",
                    markClass:"show-machine-count",
                    name:data || 0
                }];
            return btnTextTemplate(context);
        }
    },
    ellipsisData("create_time"),
    ellipsisData("creator_name"),
    longTextData("mark", "group_name", "备注信息"),
    {
        "data":null,
        "render":function(data, type, full, meta){
            if (data.id == GLOBAL_PARAM.SLAVE_MACHINE_NO_GROUP_ID) {
                return '';
            }

            var context = [{
                title:"编辑",
                markClass:"object-edit",
                iconFont:"&#xe6df;"
            },{
                title:"删除",
                markClass:"object-del",
                iconFont:"&#xe6e2;"
            }];
            return btnIconTemplate(context);
        }
    }];

var eventList = {
    "#add-object":function(){
        publish.renderParams.editPage.modeFlag = 0;
        layer_show("添加执行机组", editHtml, editPageWidth, editPageHeight.add, 1);
        publish.init();
    },
    "#batch-op":function(){
        layer.confirm(
            '请选择你需要进行的批量操作:',
            {
                title:'批量操作',
                btn:['删除', '取消'],
                shadeClose:true,
            },function(index){
                layer.close(index);
                batchOp($(".selectGroup:checked"), REQUEST_URL.WEB_EXECUTION_MACHINE_GROUP.delGroup, "删除", null, "id");
            },function(index){
                layer.close(index);
            });
    },
    ".object-edit":function(){
        var data = table.row( $(this).parents('tr') ).data();

        if (data.id == GLOBAL_PARAM.SLAVE_MACHINE_NO_GROUP_ID) {
            layer.msg('不能编辑默认组!', {time:1600});
            return;
        }

        publish.renderParams.editPage.modeFlag = 1;
        publish.renderParams.editPage.objId = data.id;
        publish.renderParams.editPage.currentObj = data;
        layer_show("编辑执行机组信息", editHtml, editPageWidth, editPageHeight.edit, 1);
        publish.init();
    },
    ".object-del":function(){
        var data = table.row( $(this).parents('tr') ).data();

        if (data.id == GLOBAL_PARAM.SLAVE_MACHINE_NO_GROUP_ID) {
            layer.msg('不能删除默认组!', {time:1600});
            return;
        }

        opObj("确认要删除此执行机组吗？", REQUEST_URL.WEB_EXECUTION_MACHINE_GROUP.delGroup, {id:data.id}, this, "删除成功!");
    },
    ".show-machine-count": function(){
        var data = table.row( $(this).parents('tr') ).data();
        let url = 'webGroupMachine.html';
        if (data.id == GLOBAL_PARAM.SLAVE_MACHINE_NO_GROUP_ID) {
            url = 'webExecutionMachine.html';
        }

        layer_show(data.group_name + "-执行机管理", url + "?group_id=" + data.id, null, null, 2);
    },
    '#download-slave': function(){
        window.open(REQUEST_URL.WEB_EXECUTION_MACHINE.downloadSlave);
    }
};

var mySetting = {
    eventList:eventList,
    templateCallBack:function(df){

        df.resolve();
    },
    listPage:{
        listUrl:REQUEST_URL.WEB_EXECUTION_MACHINE_GROUP.listGroup,
        tableObj:".table-sort",
        columnsSetting:columnsSetting,
        columnsJson:[0, 7],
        dtOtherSetting:{
            serverSide:false,
            order: [[ 1, 'asc' ]]
        }
    },
    editPage:{
        editUrl:REQUEST_URL.WEB_EXECUTION_MACHINE_GROUP.editGroup,
        getUrl:REQUEST_URL.WEB_EXECUTION_MACHINE_GROUP.getGroup,
        rules:{
            group_name:{
                required:true,
                minlength:2,
                maxlength:255
            }
        }
    },
    templateParams:templateParams
};

$(function(){
    publish.renderParams = $.extend(true,publish.renderParams,mySetting);
    publish.init();
});
